package com.twu.biblioteca;

import java.util.ArrayList;

public class Inventory {
    ArrayList<Book> books;
    ArrayList<Movie> movies;

    public Inventory()
    {
        books = new ArrayList<Book>();
        movies = new ArrayList<Movie>();

        books = new ArrayList<Book>();
        movies = new ArrayList<Movie>();

        books.add(new Book("Test-Driven Development"));
        books.add(new Book("Agile Samuri"));
        books.add(new Book("Head First Java"));
        books.add(new Book("Algortitms"));
        books.add(new Book("Extreme Programming Explained"));
        books.add(new Book("50 Shades of Gray"));

        movies.add(new Movie("Sholay", 1975, "Ramesh Sippy", "5"));
    }

    public String getBookList() {
        String allBooks = "";
        for (Book book : books) {
            if (!allBooks.equals(""))
                allBooks += "\n";
            allBooks += book.toString();
        }

        return allBooks;
    }

    public String getAvailableBookList() {
        String availableBooks = "";

        for (Book book : books) {
            if (!book.isReserved()) {
                if (!availableBooks.equals(""))
                    availableBooks += "\n";
                availableBooks += book.toString();
            }
        }

        return availableBooks;
    }

    public String getReservedBookList() {
        String reservedBooks = "";
        for (Book book : books) {
            if (book.isReserved()) {
                if (!reservedBooks.equals(""))
                    reservedBooks += "\n";
                reservedBooks += book.toString();
            }
        }

        return reservedBooks;

    }

    public String reserveBook(String s) {
        for (Book book : books) {
            if (s.equals(book.title()) && !book.isReserved()) {
                book.reserve();
                return s + " has been reserved";
            }
        }

        return s + " is Unavailable";


    }

    public String getMovieList() {
        String movieList = "Movie\tYear\tDirector\tRating\n";

        for (Movie movie : movies) {
            movieList += movie.toString() + "\n";
        }

        return movieList.trim();
    }
}